package com.airlines.crewassignment.service.crewdispatch.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.airlines.base.entity.dict.Select2;
import com.airlines.common.Page;
import com.airlines.crewassignment.dao.crewdispatch.AdditionalCrewMapper;
import com.airlines.crewassignment.entity.crewdispatch.AdditionalCrew;
import com.airlines.crewassignment.service.crewdispatch.AdditionalCrewService;
import com.airlines.crewassignment.service.dict.Select2Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * @author xxxx
 * @date 2018/07/11 14:15:38
 * @company xxxx Airlines
 * @description 
 */
@Service
public class AdditionalCrewServiceImpl implements AdditionalCrewService {

    @Autowired
    private AdditionalCrewMapper additionalCrewMapper;

    @Autowired
    private Select2Service select2Service;

    @Override
    public int insert(AdditionalCrew additionalCrew){
        return additionalCrewMapper.insert(additionalCrew);
    }

    @Override
    public int delete(Integer  id){
        return additionalCrewMapper.delete(id
);
    }


    @Override
    public int update(AdditionalCrew additionalCrew){
        return additionalCrewMapper.update(additionalCrew);
    }

    @Override
    public AdditionalCrew get(Integer  id){
        return additionalCrewMapper.get(id
);
    }

    @Override
    public List<AdditionalCrew> list(AdditionalCrew additionalCrew){
        return additionalCrewMapper.list(additionalCrew);
    }

    @Override
    public Page list(AdditionalCrew additionalCrew, Page page){
        PageHelper.startPage(page.getPageNumber(), page.getPageSize());
        List<AdditionalCrew> list = additionalCrewMapper.listByFuzzy(additionalCrew);
        List<Select2> airportList = select2Service.getAirportCityCnName();
        Map<String,List<Select2>> map= new HashMap<>();
        map.put("departureAirport", airportList);
        map.put("arrivalAirport", airportList);
        list = select2Service.convert(list, map);
        PageInfo<AdditionalCrew> pageInfo = new PageInfo<AdditionalCrew>(list);
        page.setTotal(String.valueOf(pageInfo.getTotal()));
        page.setRows(pageInfo.getList());
        return page;
    }




}
